package www.openteam.com.adapter.qualityCntrl;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.FQCGoodsField;

/**
 * Created by Administrator on 2018-03-29.
 */

public class FQCGoodsYeildAdp extends RecyclerView.Adapter<FQCGoodsYeildAdp.ViewHolder> {

    Context context;
    List<FQCGoodsField.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    IGoodsYeilClickBack iGoodsYeilClickBack;
    long mClickTime = 0;
    private String TAG = "FQCGoodsYeildAdp";

    public interface IGoodsYeilClickBack{
        void postdata(FQCGoodsField.DataBeanX.DataBean dataBean);
    }

    public FQCGoodsYeildAdp(Context context, List<FQCGoodsField.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    public void setiGoodsYeilClickBack(IGoodsYeilClickBack iGoodsYeilClickBack) {
        this.iGoodsYeilClickBack = iGoodsYeilClickBack;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_fqc_goodyeild, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final FQCGoodsField.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.fqcGyCustomerName.setText(dataBean.getCustName());
        holder.fqcGyProductNo.setText(dataBean.getCustCode());
        holder.fqcGyProductName.setText(dataBean.getProductName());
        holder.fqcGyProductNo.setText(dataBean.getProductCode());
        holder.fqcGyProductStandard.setText(dataBean.getSpecs());
        holder.fqcGyProjectNo.setText(dataBean.getProductno());
        holder.fqcGyWorkOrderNo.setText(dataBean.getPlanNumb());
        holder.fqcGyStorageId.setText(dataBean.getRdsno());
        holder.fqcGyStorageChildID.setText(""+dataBean.getId());
        holder.fqcGyStorageBatchNo.setText(dataBean.getBatchno());
        holder.fqcGyStorageBatchNo.setText(dataBean.getMeasureNum());
        holder.linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (System.currentTimeMillis() - mClickTime <600) {
                    if (null!=iGoodsYeilClickBack){
                        iGoodsYeilClickBack.postdata(dataBean);
                    }
                } else {
                    mClickTime = System.currentTimeMillis();
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.fqc_gy_customerName)
        TextView fqcGyCustomerName;
        @Bind(R.id.fqc_gy_productNo)
        TextView fqcGyProductNo;
        @Bind(R.id.fqc_gy_productName)
        TextView fqcGyProductName;
        @Bind(R.id.fqc_gy_productStandard)
        TextView fqcGyProductStandard;
        @Bind(R.id.fqc_gy_projectNo)
        TextView fqcGyProjectNo;
        @Bind(R.id.fqc_gy_workOrderNo)
        TextView fqcGyWorkOrderNo;
        @Bind(R.id.fqc_gy_storageId)
        TextView fqcGyStorageId;
        @Bind(R.id.fqc_gy_storageChildID)
        TextView fqcGyStorageChildID;
        @Bind(R.id.fqc_gy_storageBatchNo)
        TextView fqcGyStorageBatchNo;
        @Bind(R.id.fqc_gy_storageNo)
        TextView fqcGyStorageNo;
        @Bind(R.id.fqc_linear)
        LinearLayout linear;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
